// by Xeno
#define THIS_FILE "fn_sidefactory.sqf"
#include "x_setup.sqf"
private ["_b1", "_b2", "_b3", "_barray"];
if !(call FUNC(checkSHC)) exitWith {};

PARAMS_3(_b1,_b2,_b3);

_barray = if (!isNull _b3) then {[_b1,_b2,_b3]} else {[_b1,_b2]};

#ifdef __TT__
GVAR(sm_points_blufor) = 0;
GVAR(sm_points_opfor) = 0;
{
	_x addEventHandler ["killed", {_this call FUNC(AddSMPoints)}];
} forEach _barray;
#endif

while {true} do {
	call FUNC(mpcheck);
	if ({alive _x} count _barray == 0) exitWith {};
	sleep 5.321;
};

#ifndef __TT__
GVAR(sm_winner) = 2;
#else
if (GVAR(sm_points_blufor) > GVAR(sm_points_opfor)) then {
	GVAR(sm_winner) = 2;
} else {
	if (GVAR(sm_points_opfor) > GVAR(sm_points_blufor)) then {
		GVAR(sm_winner) = 1;
	} else {
		if (GVAR(sm_points_opfor) == GVAR(sm_points_blufor)) then {
			GVAR(sm_winner) = 123;
		};
	};
};
#endif
GVAR(sm_resolved) = true;
if (GVAR(IS_HC_CLIENT)) then {
	[QGVAR(sm_var), GVAR(sm_winner)] call FUNC(NetCallEventCTS);
};